package com.example.tnot.Teacher.CoursePart.Container.AddCourse.Adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.Container.AddCourse.ItemBean.Term;

import java.util.List;

public class SelectTermAdapter extends RecyclerView.Adapter<SelectTermAdapter.ViewHolder>{
    private List<Term> terms;
    public SelectTermAdapter(List<Term> terms) {
        this.terms = terms;
    }

    @NonNull
    @Override
    public SelectTermAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_select_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull SelectTermAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.tv_term.setText(terms.get(position).getTerm());
        holder.rb_select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if(holder.IsSelect){
//                    holder.rb_select.setSelected(true);
//                }else {
//                    for(int i = 0; i < terms.size(); i++){
//                        if(i != position){
//                            terms.get(i).setSelected(false);
//                        }
//                    }
//                }
//                holder.IsSelect = !holder.IsSelect;
            }
        });

    }

    @Override
    public int getItemCount() {
        return terms.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_term;
        boolean IsSelect;
        RadioButton rb_select;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_term = itemView.findViewById(R.id.tv_term);
            rb_select = itemView.findViewById(R.id.rb_select);
            rb_select.setSelected(false);
        }
    }
}
